package com.shunda.ysdgj.manager.controller.goods;

import com.shunda.ysdgj.manager.service.goods.GoodsSpecCategoryService;
import com.shunda.ysdgj.model.dto.base.IdsDto;
import com.shunda.ysdgj.model.dto.goods.GoodsSpecCategoryFindDto;
import com.shunda.ysdgj.model.entity.goods.GoodsSpecCategory;
import com.shunda.ysdgj.model.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品规格品类接口")
@RestController
@RequestMapping("/api/v1/admin/goods/spec/category")
@RequiredArgsConstructor
public class GoodsSpecCategoryController {

    private final GoodsSpecCategoryService goodsUnitService;

    @Operation(summary = "获取所有商品规格品类")
    @GetMapping("all")
    public ResultVo all() {
        return ResultVo.success(goodsUnitService.findAll());
    }

    @Operation(summary = "根据类型获取所有商品规格品类")
    @GetMapping("getByType/{categoryType}")
    public ResultVo getByType(@PathVariable Integer categoryType) {
        return ResultVo.success(goodsUnitService.findByType(categoryType));
    }

    @Operation(summary = "分页获取商品规格品类列表")
    @PostMapping("list")
    public ResultVo list(@RequestBody GoodsSpecCategoryFindDto goodsSpecCategoryFindDto) {
        return ResultVo.success(goodsUnitService.findByPage(goodsSpecCategoryFindDto));
    }

    @Operation(summary = "添加商品计量单位")
    @PostMapping("add")
    public ResultVo add(@RequestBody GoodsSpecCategory goodsSpecCategory) {
        if (!goodsUnitService.add(goodsSpecCategory)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "修改商品规格品类")
    @PostMapping("modify")
    public ResultVo modify(@RequestBody GoodsSpecCategory goodsSpecCategory) {
        if (!goodsUnitService.modify(goodsSpecCategory)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "删除商品规格品类")
    @PostMapping("delete")
    public ResultVo delete(@RequestBody IdsDto idsDto) {
        if (!goodsUnitService.deleteByIds(idsDto)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

}
